package club.twelveblog.tblog.utils;

import club.twelveblog.tblog.common.constants.HttpStatusConstants;
import club.twelveblog.tblog.common.dto.Result;

/**
 * 响应结果生成工具
 */
public class ResultGenerator {

    public static Result genSuccessResult() {
        Result result = new Result();
        result.setCode(HttpStatusConstants.OK.getStatus());
        result.setMessage(HttpStatusConstants.OK.getContent());
        return result;
    }

    public static Result genSuccessResult(String message) {
        Result result = new Result();
        result.setCode(HttpStatusConstants.OK.getStatus());
        result.setMessage(message);
        return result;
    }

    public static Result genSuccessResult(Object data) {
        Result result = new Result();
        result.setCode(HttpStatusConstants.OK.getStatus());
        result.setMessage(HttpStatusConstants.OK.getContent());
        result.setData(data);
        return result;
    }

    public static Result genErrorResult(int code, String message) {
        Result result = new Result();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    /**
     * @Description: 根据传入的常量和data数据返回对应result
     */
    public static Result getResultByHttp(HttpStatusConstants constants, Object data){
        Result result = ResultGenerator.genErrorResult(constants.getStatus(), constants.getContent());
        result.setData(data);
        return result;
    }

    /**
     * @Description: 根据传入的常量返回对应result
     */
    public static Result getResultByHttpNoData(HttpStatusConstants constants){
        Result result = ResultGenerator.genErrorResult(constants.getStatus(), constants.getContent());
        return result;
    }
}
